<template>
    <div>
        <el-form :model="formData" :rules="rules" inline="true" ref="formData"
                 class="demo-form-inline" style="margin-left: 100px">
            <el-row style="margin-top: 20px;">
                <el-col>
                    <el-form-item label="校区名称">
                        <el-input size="mini" v-model="formData.name" placeholder="必填"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="">
                <el-col>
                    <el-form-item label="校长名称">
                        <el-input size="mini" v-model="formData.mastername" placeholder="必填"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="">
                <el-col>
                    <el-form-item label="校长昵称">
                        <el-input size="mini" v-model="formData.masternick" placeholder="必填"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="">
                <el-col>
                    <el-form-item label="所属总校">
                        <el-select size="mini" v-model="formData.pschoolid" placeholder="所属总校">
                            <el-option
                                v-for="item in masterschoolList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-button type="primary" style="margin-left: 200px" @click="submitForm('add')">提交<i class="el-icon-upload el-icon--right"></i>
                    </el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script>
    import {mapActions, mapState, mapGetters} from 'vuex'
    import {addSchool} from '@/api/getData'

    export default {
        data() {
            return {
                value: '',
                formData: {
                    name: '',
                    mastername: '',
                    masternick: '',
                    pschoolid: '',
                }
            }
        }
        ,
        mounted() {

        }
        ,
        methods: {
            ...mapActions(['getGiftList', 'getPeriod', 'setEmpschool', 'deleteEmpschool', 'fillSchoolEmps', 'getAllSchool']),
            async submitForm(formName) {
                try {
                    var data={"data":this.formData}
                    let result = await addSchool(data);
                    if (result.success == true) {
                        this.$message({
                            type: 'success',
                            message: '添加成功'
                        });
                        this.formData = {
                            name: '',
                            mastername: '',
                            masternick: '',
                            pschoolid: '',
                        }
                        this.getAllSchool();
                    }
                } catch (err) {
                    console.log(err);
                }
            }
        }
        ,
        computed: {
            ...
                mapGetters(['schoolList','masterschoolList'])
        }
        ,
    }
</script>
<style lang="less">


    .el-form-item {
        margin-bottom: 5px;
    }

    .el-form-item__label {
        width: 120px;
        text-align: right;
    }
</style>
